package com.parktech.sun.web.controller;

import com.parktech.sun.domain.model.sunhz.Application;
import com.parktech.sun.domain.service.aboutus.AboutUsService;
import com.parktech.sun.domain.service.sunhz.ApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * User: Think
 * Date: 11-1-16
 * Time: 下午5:04
 */
@Controller
@RequestMapping("/applications")
public class ApplicationViewController extends BaseViewController {

    private ApplicationService applicationService;

    @Autowired
    private AboutUsService aboutUsService;

    @Autowired
    public ApplicationViewController(ApplicationService applicationService) {
        this.applicationService = applicationService;
    }

    @RequestMapping
    public void view(Model model) {
        List<Application> applicationList = applicationService.listAll();
        model.addAttribute(aboutUsService.getByCategory("applicationIntroduction"));
        model.addAttribute("applicationList", applicationList);
    }

    @RequestMapping("/{applicationId}")
    public String viewDetail(@PathVariable("applicationId") Long applicationId, Model model) {
        Application application = applicationService.getById(applicationId);
        model.addAttribute(application);
        return "applicationDetail";
    }
}
